package com.oracle.application.controller;

import com.oracle.application.feign.BooksFeign;
import com.oracle.application.feign.vo.Book;
import com.oracle.application.feign.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/books")
public class BooksController {

    @Autowired(required = false)
    private BooksFeign booksFeign;

    @GetMapping("/getBookName")
    public R getBooksByName(@RequestParam("bookName")String bookName){

        return new R(200,"success",booksFeign.getBooksByName(bookName));
    }


    @GetMapping("/list")
    public R list(){
        return new R(200,"success",booksFeign.list());
    }

    @PostMapping("/addBook")
    public R add(@RequestBody Book book){
        return  new R(200,"success",booksFeign.add(book));
    }

    @PutMapping("/update")
    public R update(@RequestBody Book book){
        return new R(200,"success",booksFeign.update(book));

    }

    @DeleteMapping("/deleteById")
    public R delete(@RequestParam("id") Integer id){
        return new R(200,"success",this.booksFeign.delete(id));
    }

}
